package com.kuaiditu.assistant.api.xz_api.xz_encode;

/**
 * Created by Eenie on 2017/8/11.
 * Email: eeniework@gmail.com
 * Des:
 */

public class a extends b{
    static final byte[] a = new byte[]{13, 10};
    private static final byte[] i = new byte[]{65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47};
    private static final byte[] j = new byte[]{65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 45, 95};
    private static final byte[] k = new byte[]{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};
    private final byte[] l;
    private final byte[] m;
    private final byte[] n;
    private final int o;
    private final int p;
    private int q;

    public a() {
        this(0);
    }

    public a(int var1) {
        this(var1, a);
    }

    public a(int var1, byte[] var2) {
        this(var1, var2, false);
    }

    public a(int var1, byte[] var2, boolean var3) {

        super(3, 4, var1, var2 == null ? 0 : var2.length);

        this.m = k;
        if(var2 != null) {
            if(this.c(var2)) {
                String var5 = com.kuaiditu.assistant.api.xz_api.xz_encode.c.a(var2);
                throw new IllegalArgumentException("lineSeparator must not contain base64 characters: [" + var5 + "]");
            }

            if(var1 > 0) {
                this.p = var2.length + 4;
                this.n = new byte[var2.length];
                System.arraycopy(var2, 0, this.n, 0, var2.length);
            } else {
                this.p = 4;
                this.n = null;
            }
        } else {
            this.p = 4;
            this.n = null;
        }

        this.o = this.p - 1;
        if(var3) {
            var2 = j;
        } else {
            var2 = i;
        }

        this.l = var2;
    }

    public a(boolean var1) {
        this(76, a, var1);
    }

    public static byte[] a(byte[] var0) {
        return a(var0, false);
    }

    public static byte[] a(byte[] var0, boolean var1) {
        return a(var0, var1, false);
    }

    public static byte[] a(byte[] var0, boolean var1, boolean var2) {
        return a(var0, var1, var2, 2147483647);
    }

    public static byte[] a(byte[] var0, boolean var1, boolean var2, int var3) {
        byte[] var6 = var0;
        if(var0 != null) {
            if(var0.length == 0) {
                var6 = var0;
            } else {
                a var7;
                if(var1) {
                    var7 = new a(var2);
                } else {
                    var7 = new a(0, a, var2);
                }

                long var4 = var7.d(var0);
                if(var4 > (long)var3) {
                    throw new IllegalArgumentException("Input array too big, the output array would be bigger (" + var4 + ") than the specified maximum size of " + var3);
                }

                var6 = var7.b(var0);
            }
        }

        return var6;
    }

    void a(byte[] var1, int var2, int var3) {
        if(!this.f) {
            if(var3 < 0) {
                this.f = true;
                if(this.h != 0 || this.c != 0) {
                    this.a(this.p);
                    var2 = this.e;
                    switch(this.h) {
                        case 1:
                            var1 = this.d;
                            var3 = this.e;
                            this.e = var3 + 1;
                            var1[var3] = (byte)this.l[this.q >> 2 & 63];
                            var1 = this.d;
                            var3 = this.e;
                            this.e = var3 + 1;
                            var1[var3] = (byte)this.l[this.q << 4 & 63];
                            if(this.l == i) {
                                var1 = this.d;
                                var3 = this.e;
                                this.e = var3 + 1;
                                var1[var3] = (byte)61;
                                var1 = this.d;
                                var3 = this.e;
                                this.e = var3 + 1;
                                var1[var3] = (byte)61;
                            }
                            break;
                        case 2:
                            var1 = this.d;
                            var3 = this.e;
                            this.e = var3 + 1;
                            var1[var3] = (byte)this.l[this.q >> 10 & 63];
                            var1 = this.d;
                            var3 = this.e;
                            this.e = var3 + 1;
                            var1[var3] = (byte)this.l[this.q >> 4 & 63];
                            var1 = this.d;
                            var3 = this.e;
                            this.e = var3 + 1;
                            var1[var3] = (byte)this.l[this.q << 2 & 63];
                            if(this.l == i) {
                                var1 = this.d;
                                var3 = this.e;
                                this.e = var3 + 1;
                                var1[var3] = (byte)61;
                            }
                    }

                    var3 = this.g;
                    this.g = this.e - var2 + var3;
                    if(this.c > 0 && this.g > 0) {
                        System.arraycopy(this.n, 0, this.d, this.e, this.n.length);
                        this.e += this.n.length;
                    }
                }
            } else {
                for(int var4 = 0; var4 < var3; ++var2) {
                    this.a(this.p);
                    this.h = (this.h + 1) % 3;
                    byte var6 = var1[var2];
                    int var5 = var6;
                    if(var6 < 0) {
                        var5 = var6 + 256;
                    }

                    this.q = var5 + (this.q << 8);
                    if(this.h == 0) {
                        byte[] var7 = this.d;
                        var5 = this.e;
                        this.e = var5 + 1;
                        var7[var5] = (byte)this.l[this.q >> 18 & 63];
                        var7 = this.d;
                        var5 = this.e;
                        this.e = var5 + 1;
                        var7[var5] = (byte)this.l[this.q >> 12 & 63];
                        var7 = this.d;
                        var5 = this.e;
                        this.e = var5 + 1;
                        var7[var5] = (byte)this.l[this.q >> 6 & 63];
                        var7 = this.d;
                        var5 = this.e;
                        this.e = var5 + 1;
                        var7[var5] = (byte)this.l[this.q & 63];
                        this.g += 4;
                        if(this.c > 0 && this.c <= this.g) {
                            System.arraycopy(this.n, 0, this.d, this.e, this.n.length);
                            this.e += this.n.length;
                            this.g = 0;
                        }
                    }

                    ++var4;
                }
            }
        }

    }

    protected boolean a(byte var1) {
        boolean var2;
        if(var1 >= 0 && var1 < this.m.length && this.m[var1] != -1) {
            var2 = true;
        } else {
            var2 = false;
        }

        return var2;
    }
}
